#include "stdafx.h"
#include "shader.h"
#include "arg_seter.h"

shader::shader():
m_id(SHADER_NULL),
m_file_name(""),
m_vertex_element(0),
m_world(0),m_view(0),m_view_proj(0)
{
	m_world=new LTMatrix;
	m_view=new LTMatrix;
	m_view_proj=new LTMatrix;


}

void shader::term()
{
	if (m_vertex_element)
	{
		delete[] m_vertex_element;
		m_vertex_element=0;
	}
	if (m_world)
	{
		delete m_world;
		m_world=0;
	}
	if (m_view)
	{
		delete m_view;
		m_view=0;
	}
	if (m_view_proj)
	{
		delete m_view_proj;
		m_view_proj=0;
	}


}

void shader::default_set_args( LTEffectShader *pEffect,const LTShaderDeviceState &ShaderDeviceState )
{
	return;
}

void shader::set_args( HOBJECT hObj,LTEffectShader *pEffect,const LTShaderDeviceState &ShaderDeviceState )
{
	static SETER_COLL::iterator it; 
	it=m_seters.find(hObj);
	if (it!=m_seters.end())
	{
		it->second->set_args(pEffect,ShaderDeviceState);
		//do something
	}
	else
	{
		default_set_args(pEffect,ShaderDeviceState);
	}
			

}

void shader::add_seter( arg_seter*_seter )
{
	HOBJECT hObj=_seter->get_obj();
	SETER_COLL::iterator it=m_seters.find(hObj);
	if (it!=m_seters.end())
	{
		return;
	}
	m_seters.insert(std::make_pair(hObj,_seter));

}